<template>
   <div>
    <div v-if="mode === 'DESIGN'">
      <el-select class="max-fill" v-if="!expanding" v-model="_value" disabled :placeholder="placeholder" size="default"/>
      <el-radio-group v-model="_value" v-else size="default">
        <el-radio class="w-row-text" style="margin: 5px" disabled v-for="(op, index) in options" :key="index" :label="op">{{ op }}</el-radio>
      </el-radio-group>
    </div>
    <div v-else-if="mode === 'PC' && !readonly">
      <el-select class="max-fill" v-if="!expanding" v-model="_value" clearable :placeholder="placeholder" size="default">
        <el-option v-for="(op, index) in options" :key="index" :value="op" :label="op"></el-option>
      </el-select>
      <el-radio-group v-model="_value" v-else size="default">
        <el-radio class="w-row-text" style="margin: 5px" v-for="(op, index) in options" :key="index" :label="op">{{ op }}</el-radio>
      </el-radio-group>
    </div>
    <div v-else-if="mode === 'MOBILE' && !readonly">
      <!--      <div v-if="!expanding">
          <field right-icon="arrow" readonly clickable :value="_value" :placeholder="placeholder" @click="showPicker = true"/>
          <popup v-model="showPicker" position="bottom">
            <picker :title="placeholder" show-toolbar :columns="options" @confirm="onConfirm" @cancel="showPicker = false"></picker>
          </popup>
        </div>-->
      <radio-group v-model="_value" direction="horizontal" size="default">
        <radio style="margin: 5px" v-for="(op, index) in options" :key="index" :name="op">{{ op }}</radio>
      </radio-group>
    </div>
    <div v-else>
      {{ _value }}
    </div>
  </div>
</template>

<script>
import { Field, Popup, Picker, Radio, RadioGroup } from 'vant'
import componentMinxins from '/@/views/setting/workflow/components/ComponentMinxins'
import { reactive, toRefs, computed } from 'vue'

export default {
  name: 'SelectInput',
  mixins: [componentMinxins],
  components: { Radio, RadioGroup, Picker, Field, Popup },
  props: {
    modelValue: {
      type: String,
      default: null,
    },
    placeholder: {
      type: String,
      default: '请选择选项',
    },
    expanding: {
      type: Boolean,
      default: false,
    },
    options: {
      type: Array,
      default: () => {
        return []
      },
    },
  },
  emits: ['update:modelValue'],
  setup(props) {
    const { modelValue } = toRefs(props)
    const state = reactive({
        showPicker: false,
    })
    const _value = computed({
        get: () => {
            return modelValue.value
        },
        set: val => {
            context.emit('update:modelValue', val)
        }
    }) 
    const onConfirm = () => {
        state.showPicker = false
        _value.value = val
    }
    return {
        ...toRefs(state),
        onConfirm,
        _value
    }
  }
}
</script>

<style>

</style>